﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Sec_scan安全漏洞扫描系统_2._0.HomeForm
{
    public partial class TaskAdd : Form
    {
        public TaskAdd()
        {
            InitializeComponent();
            StartPosition = FormStartPosition.CenterScreen;
        }

        private void TaskAdd_Load(object sender, EventArgs e)
        {

        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            if(checkBox2.Checked == true)
            {
                checkBox1.Checked = false;
            }
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked == true)
            {
                checkBox2.Checked = false;
            }
        }

        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox3.Checked == true)
            {
                checkBox4.Checked = false;
            }
        }

        private void checkBox4_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox4.Checked == true)
            {
                checkBox3.Checked = false;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < checkedListBox1.Items.Count; i++)
            {
                checkedListBox1.SetItemChecked(i, true);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < checkedListBox1.Items.Count; i++)
            {
                checkedListBox1.SetItemChecked(i, false);
            }
        }
        /// <summary>
        /// 创建任务
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void button5_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBox1.Text))
            {
                MessageBox.Show("任务名称不能为空！");
            }
            else
            {
                var selectedValues = GetCheckedItems(checkedListBox1);
                if (selectedValues.Count > 0)
                {
                    // 将这个值存入数据库，然后获取的时候取;分隔
                    string values = string.Join("; ", selectedValues);
                    //Console.WriteLine(values);
                    MessageBox.Show("已选择的项: " + string.Join("; ", selectedValues));
                }
                else
                {
                    MessageBox.Show("请至少选择一项任务！");
                }
            }
        }
        private System.Collections.Generic.List<string> GetCheckedItems(CheckedListBox checkedListBox)
        {
            var checkedItems = new System.Collections.Generic.List<string>();

            // 遍历 CheckedItems，获取每个选中项的值
            foreach (var item in checkedListBox.CheckedItems)
            {
                checkedItems.Add(item.ToString()); // 将选中项的值添加到列表中
            }

            return checkedItems;
        }
    }
}
